'use strict';

/**
 * @ngdoc service
 * @name htmsMobileApp.urlObj2Str
 * @description
 * # urlObj2Str
 * Service in the htmsMobileApp.
 */
angular.module('htmsMobileApp')
  .service('urlObj2Str', function () {
    return {
      getUrlStr : function(searchObj){
        var url = searchObj.apiUrl;
        var page = searchObj.page;
        var size = searchObj.pageSize;
        var sortType = searchObj.sortType;
        var search = searchObj.search;
        var flag = false;
        if(url != undefined){
          if(page != undefined || size != undefined || search != undefined){
            url += "?";
            if(page != undefined){
              url += "page=";
              url += page;
              flag = true;
            }
            if(size != undefined){
              if(flag == true){
                url += "&";
              }
              url += "page.size=";
              url += size;
              flag = true;
            }
            if(sortType != undefined){
              if(flag == true){
                url += "&";
              }
              url += "sortType=";
              url += sortType;
              flag = true;
            }
            if(search != undefined && search.length > 0){
              if(flag == true){
                url += "&";
              }
              if(search.length != undefined&&search.length >0){
                for(var i = 0;i < search.length;i++){
                  url += search[i].key;
                  url += "=";
                  url += search[i].value;
                  if(i != search.length - 1){
                    url += "&";
                  }
                }
              }
            }
          }
        }
        return url;
      }
    }

  });
